#pragma once 

#include <iostream>
using namespace std;
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <strings.h>

class InetAddr
{
public:
    InetAddr()
    {}

    InetAddr(struct sockaddr_in addr) :_addr(addr)
    {
        _ip = inet_ntoa(_addr.sin_addr);
        _port = ntohs(_addr.sin_port);
    }

    InetAddr(std::string ip, uint16_t port) :_ip(ip), _port(port)
    {
        bzero(&_addr, sizeof(_addr));
        _addr.sin_family = AF_INET;
        _addr.sin_port = htons(_port);
        _addr.sin_addr.s_addr = inet_addr(_ip.c_str());
    }

    bool operator==(InetAddr& addr)
    {
        return _ip == addr.Ip() && _port == addr.Port();
    }

    // void operator=(struct sockaddr_in& addr)
    // {   
    //     _addr = addr;
    //     InitAddress(&_ip, &_port);
    // }

    std::string Ip()
    {
        return _ip;
    }

    uint16_t Port()
    {
        return _port;
    }

    struct sockaddr_in Addr()
    {
        return _addr;
    }

    ~InetAddr()
    {}
private:
    struct sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;
};